#include "core/GameConteiner.h"
#include "util/tinyxml2.h"

#include "game/cutscenes/Intro.h"
#include "game/stages/Stg01Venenosa.h"
#include "game/stages/Stg02Venenosa.h"

#include <iostream>

using namespace tinyxml2;
using namespace eats_core;
using namespace std;

GameConteiner * GameConteiner::game = NULL;
std::string GameConteiner::fileLocation = "/opt/attacks/resources/configuration.xml";

GameConteiner::GameConteiner()
{

}

GameConteiner::~GameConteiner()
{
    //dtor
}

bool GameConteiner::config(std::string  file )
{
    XMLDocument doc;
    const char * tempString = "";

    int sizeW, sizeH;

    if ( doc.LoadFile( file.c_str() ) )
    {
        std::cout << "Log | ERRO :: Erro ao ler do arquivo = " << file << ". Impossível continuar..." << std::endl;
        exit(-1);
    }

    XMLNode * gameManagerNode = doc.RootElement();

    if ( gameManagerNode != NULL )
    {

        tempString = gameManagerNode -> FirstChildElement( "sizeW" )->FirstChild()->ToText()->Value();
        //(std::strcmp(tempString , "default") == 0 || std::strcmp(tempString, "") != 0 ) ? sizeW = 800 : sizeW = (int) tempString;

        tempString = gameManagerNode -> FirstChildElement( "sizeH" )->FirstChild()->ToText()->Value();
        //(std::strcmp(tempString , "default") == 0 || std::strcmp(tempString, "") != 0 ) ? sizeH = 600 : sizeW = (int) tempString;

        gameManager = new GameManager();

		if ( gameManager->setUp() == false )
		{
			return false;
		}

		Intro * introducao = new Intro();
		introducao->_canonical_name = "Introducao.";

		Stg_01_Venenosa * venenosa01 = new Stg_01_Venenosa("/opt/attacks/resources/mapa01.txt");
		venenosa01->_canonical_name = "Estagio 01";

		Stg02Venenosa * venenosa02 = new Stg02Venenosa("/opt/attacks/resources/mapa02.txt");
		venenosa02->_canonical_name = "Estagio 02";

        gameManager -> statePush( introducao );
        gameManager -> statePush( venenosa01 );
        gameManager -> statePush( venenosa02 );

    }

    gameManager->_current_state = gameManager->getState(0);

    return true;

}
